<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">

var http = createRequestObject();
var timeout = 15 * 1000;

function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }

   return req;

}

function sendRequest() {
	document.getElementById("spinner").src = "spinner.gif";
	http.open('get', 'wootcheck_ajax.html');
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4 && http.status == 200) {
		var response = http.responseText;

		if(response) {
			var a = response.split("||");
			var old = document.getElementById("item").innerHTML;
			document.getElementById("percent").innerHTML = a[0];
			var per = "0%";
			if(a[0].indexOf('%') < 0) {
				per = "0%";
			} else {
				per = a[0].substring(0,a[0].indexOf('%')+1);
			}
			document.getElementById("bar").style.width = per;
			document.title = a[0];
			document.getElementById("lastupdated").innerHTML = "Last update: " + a[2];
			if(a[5] <= 0) {
				document.getElementById("timeleft").innerHTML = "Time Left: Not enough information to determine";
			} else {
				document.getElementById("timeleft").innerHTML = "Time left: " + a[5] + " seconds.";
			}
			var newp = 'Product is ' + a[1];
			document.getElementById("item").innerHTML = newp;
			document.getElementById("price").innerHTML = a[4];
			if(a[3] != "0") {
				document.getElementById("wantone").innerHTML = "<a href='http://www.woot.com/" + a[3] + "'>Want One</a>";
			} else {
				document.getElementById("wantone").innerHTML = "Item is sold out";
			}
			if(old[16] != newp[16] && old != "") {
				window.location.reload(true);
			}
			document.getElementById("spinner").src = "";
		}
	} else {
		document.getElementById("spinner").src = "";
	}
}

function periodicUpdate() {
	sendRequest();
	setTimeout("periodicUpdate()", timeout);
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Woot-Off Checker</title>
<style type="text/css" media="screen">
<!--
* {margin:0;padding:0;}
body {
	background: #FFFFFF;
	font: 16px "Lucida Grande","Trebuchet MS",   Arial, Helvetica, sans-serif;
	padding:20px;
}

p {
	padding:5px;
	font-family:georgia, verdana, arial, sans-serif;
	line-height: 22px; 
	letter-spacing:1px;
}
p.sub {
	font-size:14px;
	line-height: 20px;
	margin-top:10px;
	border-top:1px solid #e9e9e9;
	width:90%;
}

a {color: #CC0000;}
a:hover {color:#0066CC; text-decoration:none;}

h1,h2{padding-bottom:2px;margin-bottom:5px;}
h1{border-bottom:2px solid #FF9933;width:90%;color:#336666;}
h2{color:#CC0000;}
-->
</style>
</head>
<body onLoad='periodicUpdate()'>
<h1>Woot-off Checker -- AJAX Edition</h1>
<p><em><strong>This page will auto-update. Please do not reload the page!</strong></em></p>
<img src="" id="spinner" />
<h2><div id='percent'></div></h2>
<div style='background-color:black;width:500px;height:20px;'>
<div style='background-color:#f93;width:100%;position:relative;left:3px;top:3px;height:14px;' id='bar'>
&nbsp;
</div>
</div>
<h2><div id='item'></div></h2>
<h5><div id='price'></div></h5>
<h5><div id='lastupdated'></div></h5>
<h5><div id='timeleft'></div></h5>
<div id='wantone'></div>
<img src='woot.jpg'>
<p>This page uses a cache from up to 10 seconds ago, refreshes every 15 seconds.</p>
<p>Cache implemented to slow killing of woot servers</p>
<p class="sub"><a href="http://www.woot.com/" target="_blank">http://www.woot.com/</a> -
  AJAX and DB code created by yellowBkpk. Modified code from <a href="http://black2d.com/" target="_blank">Black2d</a>. Modified by <a href="http://www.outsideofdreams.com/" target="_blank">Ekimus</a> with the help of <a href="http://Cainkar.com/woot" target="_blank">Cainkar</a> <a href="http://black2d.com/woot" target="_blank">Download
  the source</a></p>
</body>
</html>

